Null Pointer Exception even after a check conditon